<?php
namespace App\Utils;

/**
 * 角色权限管理工具类
 * @package App\Utils
 */
class RolesUtil
{
    /**
     * 返回全部的权限配置数组
     */
    public static function allPermissions()
    {
        return array(
            [//信息管理=====================================================================================
                "permission" => "purview.news",
                "title"      => "信息管理",
                "des"        => "是否能够操作信息管理区域？",
                "super"      => false,
                "parent"     => null],
            [
                "permission" => "permission.classify",
                "title"      => "操作信息分类",
                "des"        => "是否可以编辑/删除信息的分类.",
                "super"      => false,
                "parent"     => "purview.news"
            ],
            [
                "permission" => "permission.news",
                "title"      => "文章编辑",
                "des"        => "是否可以编辑/删除文章.",
                "super"      => false,
                "parent"     => "purview.news"
            ],
            [
                "permission" => "permission.bulletin",
                "title"      => "系统公告",
                "des"        => "是否可以编辑/删除系统公告.",
                "super"      => false,
                "parent"     => "purview.news"
            ],
            [
                "permission" => "permission.feedback",
                "title"      => "会员咨询",
                "des"        => "是否可以查看/回复会员的问题咨询.",
                "super"      => false,
                "parent"     => "purview.news"
            ],

            [//系统设置=====================================================================================
                "permission" => "purview.setting",
                "title"      => "系统设置",
                "des"        => "是否能够操作系统设置区域？",
                "super"      => false,
                "parent"     => null],
            [
                "permission" => "permission.webinfo",
                "title"      => "站点信息设置",
                "des"        => "控制站点的名称和站点关闭/开启功能.",
                "super"      => false,
                "parent"     => "purview.setting"
            ],
            [
                "permission" => "permission.admins",
                "title"      => "管理员管理",
                "des"        => "添加/删除/查看后台系统的管理员.",
                "super"      => false,
                "parent"     => "purview.setting"
            ],
            [
                "permission" => "permission.logs",
                "title"      => "系统日志",
                "des"        => "查看后台系统的所有管理员操作日志.",
                "super"      => false,
                "parent"     => "purview.setting"
            ],

        );
    }

    /**
     * 获取全部的区域级权限
     */
    public static function allParent($permissions)
    {
        $parent = array();
        foreach ($permissions as $permission) {
            if (empty($permission['parent'])) {
                $parent[] = $permission;
            }
        }
        return $parent;
    }

    /**
     * 获取区域级权限下级的所有权限
     */
    public static function allChild($parent, $permissions)
    {
        $child = array();
        foreach ($permissions as $permission) {
            if ($permission['parent'] == $parent) {
                $child[] = $permission;
            }
        }
        return $child;
    }

    /**
     *
     */
    public static function canPermission()
    {

    }
}